<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;
use EasyWeChat\Foundation\Application;
use addons\wechat\library\Config as ConfigService;

class Article extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function list()
    {
        $article = Db::name('article')->order('id desc')->paginate(15);
        $page = $article->render();
        $this->assign('article', $article);
        $this->assign('page', $page);
        $this->assign('title', '商情瞭望 —— 行业动态');
        return $this->view->fetch();
    }

    public function info($id)
    {
        $info = Db::name('article')->where(['id' => $id])->find();
        if(!$info) {
            $this->error('页面不存在');
        }
        $this->assign('title', $info['title']);
        // 分享
        $app = new Application(ConfigService::load());
        $js = $app->js;
        $this->assign('js', $js);
        $this->assign('info', $info);
        return $this->view->fetch();
    }

}
